﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GtaAPIClient.XhDoOrderService;
using GtaAPIClient.XhDoQueryService; 
using GtaAPIClient.TransactionManage; 
using GtaAPIClient.DoRZRJOrderService;
using GtaAPIClient.DoRZRJQueryService;
using GtaAPIClient.WcfRZRJBasicProviderService;
using GtaAPIClient.CounterComprehensiveService;
using GtaAPIClient.DoCommonQuery;

namespace GtaAPIClient
{
    class WcfServiceImpl : WcfService
    {      
        /**************************账户管理*******************************/
        public TransactionManage.UM_UserInfo[] batchOpenAccount(out string outMessage, int number, InitFund inifund, string loginName, string loginPswd)
        {
            TransactionManage.TransactionManageClient transactionManageClient = new TransactionManageClient();
            try
            {
                TransactionManage.UM_UserInfo[] t = transactionManageClient.BatchAddTransaction(out outMessage, number, inifund, loginName, loginPswd);
                transactionManageClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (transactionManageClient != null)
                {
                    transactionManageClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public TransactionManage.UM_UserInfo openAccount(out GtaAPIClient.TransactionManage.AccountEntity[] accountEntitys, out string outMessage, TransactionManage.UM_UserInfo userInfo, InitFund inifund, string mloginName, string mloginPswd)
        {
            TransactionManage.TransactionManageClient transactionManageClient = new TransactionManageClient();
            try
            {
                TransactionManage.UM_UserInfo t = transactionManageClient.AddTransactionFP(out accountEntitys, out outMessage, mloginName, mloginPswd, userInfo, inifund);
                transactionManageClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (transactionManageClient != null)
                {
                    transactionManageClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public bool fundTransfer(out string outMessage, int tradeId, int fromCapitalAccountType, int toCapitalAccountType, decimal transferAmount, int currencyType)
        {
            TransactionManage.TransactionManageClient transactionManageClient = new TransactionManageClient();
            try
            {
                bool t = transactionManageClient.ConvertFreeTransferEntityFP(out outMessage, tradeId, fromCapitalAccountType, toCapitalAccountType, transferAmount, currencyType);
                transactionManageClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (transactionManageClient != null)
                {
                    transactionManageClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public AccountFindResultEntity[] findAccount(out string message, int accountType, string traderId, string password)
        {
            TransactionManage.TransactionManageClient transactionManageClient = new TransactionManageClient();
            try
            {
                AccountFindResultEntity[] t = transactionManageClient.FindAccount(out message, accountType, traderId, password);
                transactionManageClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (transactionManageClient != null)
                {
                    transactionManageClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /**************************行情*******************************/
        public MarketDataLevel getStockQuotation(out string errMsg, string code, int breedClassType)
        {
            CounterComprehensiveService.CounterComprehensiveServiceClient counterComprehensiveServiceClient = new CounterComprehensiveServiceClient();
            try
            {
                MarketDataLevel t = counterComprehensiveServiceClient.GetMarketDataInfoByCode(out errMsg, code, breedClassType);
                counterComprehensiveServiceClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (counterComprehensiveServiceClient != null)
                {
                    counterComprehensiveServiceClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /**************************现货*******************************/
        public OrderResponse doOrder(XhDoOrderService.StockOrderRequest stockOrderReq)
        {
            XhDoOrderService.DoOrderClient doOrderClient = new DoOrderClient();
            try
            { 
                OrderResponse t = doOrderClient.DoStockOrder(stockOrderReq);
                doOrderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doOrderClient != null)
                {
                    doOrderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool cancelOrder(string orderId, ref string message, out GTTypesOrderStateType ost)
        {
            XhDoOrderService.DoOrderClient doOrderClient = new DoOrderClient();
            try
            { 
                bool t = doOrderClient.CancelStockOrder(orderId, ref message, out ost); 
                doOrderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doOrderClient != null)
                {
                    doOrderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public long getMaxOrderAmount(out string outMessage, string TraderId, float OrderPrice, string Code, CounterComprehensiveService.GTTypesOrderPriceType orderPriceType)
        {
            CounterComprehensiveService.CounterComprehensiveServiceClient counterComprehensiveServiceClient = new CounterComprehensiveServiceClient();
            try
            {
                long t = counterComprehensiveServiceClient.GetSpotMaxOrderAmount(out outMessage, TraderId, OrderPrice, Code, orderPriceType);
                counterComprehensiveServiceClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (counterComprehensiveServiceClient != null)
                {
                    counterComprehensiveServiceClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public DoCommonQuery.XH_TodayEntrustTableInfo[] queryOrder(out int total, out string errorMessage, string userID, string pwd, int accountType, DoCommonQuery.SpotEntrustConditionFindEntity filter, DoCommonQuery.PagingInfo pageInfo)
        {
            DoCommonQuery.TraderQueryClient commonQueryClient = new DoCommonQuery.TraderQueryClient();
            try
            { 
                DoCommonQuery.XH_TodayEntrustTableInfo[] t = commonQueryClient.PagingQueryXH_TodayEntrustInfoByFilterAndUserIDPwd(out total, out errorMessage, userID, pwd, accountType, filter, pageInfo);
                commonQueryClient.Abort();
                return t;  
            }
            catch (Exception ex)
            {
                if (commonQueryClient != null)
                {
                    commonQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        /** 国泰安中该方法有错误
        public XhDoQueryService.XH_TodayEntrustTableInfo[] queryOrder(out int count, string capitalAccount, string strPassword, XhDoQueryService.SpotEntrustConditionFindEntity cond, int start, int page, ref string errorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            
            try
            {  
                XhDoQueryService.XH_TodayEntrustTableInfo[] t = doQueryClient.SpotTodayEntrustFindByXhCapitalAccount(out count, capitalAccount, strPassword, cond, start, page, ref errorMessage);
                doQueryClient.Abort();
                return t; 
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }*/


        public XhDoQueryService.XH_HistoryEntrustTableInfo[] queryHistoryOrder(out int count, out string errorMessage, string capitalAccount, string strPassword, int start, int page, XhDoQueryService.SpotEntrustConditionFindEntity cond)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.XH_HistoryEntrustTableInfo[] t = doQueryClient.SpotHistoryEntrustFind(out count, out errorMessage, capitalAccount, strPassword, start, page, cond);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.XH_TodayTradeTableInfo[] queryTrade(out int count, out string strErrorMessage, string capitalAccount, string strPassword, int start, int page, XhDoQueryService.SpotTradeConditionFindEntity cond)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.XH_TodayTradeTableInfo[] t = doQueryClient.SpotTodayTradeFindByCapitalAccount(out count, out strErrorMessage, capitalAccount, strPassword, start, page, cond);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.XH_HistoryTradeTableInfo[] queryHistoryTrade(out int count, out string strErrorMessage, string capitalAccount, string strPassword, int start, int page, XhDoQueryService.SpotTradeConditionFindEntity cond)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.XH_HistoryTradeTableInfo[] t = doQueryClient.SpotHistoryTradeFind(out count, out strErrorMessage, capitalAccount, strPassword, start, page, cond);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.SpotHoldFindResultEntity[] queryHold(out int count, string capitalAccount, string strPassword, XhDoQueryService.SpotHoldConditionFindEntity cond, int start, int page, ref string strErrorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.SpotHoldFindResultEntity[] t = doQueryClient.SpotHoldFind(out count, capitalAccount, strPassword, cond, start, page, ref strErrorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.SpotCapitalEntity getSpotCapital(string strFundAccountId, XhDoQueryService.TypesCurrencyType currencyType, string userPassword, ref string strErrorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.SpotCapitalEntity t = doQueryClient.SpotCapitalFind(strFundAccountId, currencyType, userPassword, ref strErrorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        //获得用户所有账号的资产信息，目前还未用到
        public XhDoQueryService.AssetSummaryEntity[] getAssetsSummary(out string outMessage, string traderId, string password)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.AssetSummaryEntity[] t = doQueryClient.AssetSummaryFind(out outMessage, traderId, password);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /**************************股指期货*******************************/
        public OrderResponse doIfOrder(XhDoOrderService.StockIndexFuturesOrderRequest futuresorder)
        {
            XhDoOrderService.DoOrderClient doOrderClient = new DoOrderClient();
            try
            {
                OrderResponse t = doOrderClient.DoStockIndexFuturesOrder(futuresorder); 
                doOrderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doOrderClient != null)
                {
                    doOrderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool cancelIfOrder(string orderId, ref string message, out GTTypesOrderStateType ost)
        {
            XhDoOrderService.DoOrderClient doOrderClient = new DoOrderClient();
            try
            {
                bool t = doOrderClient.CancelStockIndexFuturesOrder(orderId, ref message, out ost); 
                doOrderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doOrderClient != null)
                {
                    doOrderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public long getIfMaxOrderAmount(out string outMessage, string TraderId, float OrderPrice, string Code, CounterComprehensiveService.GTTypesOrderPriceType orderPriceType)
        {
            CounterComprehensiveService.CounterComprehensiveServiceClient counterComprehensiveServiceClient = new CounterComprehensiveServiceClient();
            try
            {
                long t = counterComprehensiveServiceClient.GetFutureMaxOrderAmount(out outMessage, TraderId, OrderPrice, Code, orderPriceType);
                counterComprehensiveServiceClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (counterComprehensiveServiceClient != null)
                {
                    counterComprehensiveServiceClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public decimal getIfTradeFee(out string errMsg, CounterComprehensiveService.StockIndexFuturesOrderRequest stockorder)
        {
            CounterComprehensiveService.CounterComprehensiveServiceClient counterComprehensiveServiceClient = new CounterComprehensiveServiceClient();
            try
            {
                decimal t = counterComprehensiveServiceClient.GetStockIndexFuturesPreDealCost(out errMsg, stockorder);
                counterComprehensiveServiceClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (counterComprehensiveServiceClient != null)
                {
                    counterComprehensiveServiceClient.Abort(); 
                }
                throw new Exception(ex.Message);
            } 
        }


        public XhDoQueryService.QH_TodayEntrustTableInfo[] queryIfOrder(out int count, string capitalAccount, string strPassword, XhDoQueryService.FuturesEntrustConditionFindEntity cond, int start, int page, ref string errorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.QH_TodayEntrustTableInfo[] t = doQueryClient.FuturesTodayEntrustFindByQhCapitalAccount(out count, capitalAccount, strPassword, cond, start, page, ref errorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.QH_HistoryEntrustTableInfo[] queryIfHistoryOrder(out int count, string capitalAccount, string strPassword, XhDoQueryService.FuturesEntrustConditionFindEntity cond, int start, int page, ref string errorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.QH_HistoryEntrustTableInfo[] t = doQueryClient.FuturesHistoryEntrustFindByQhCapitalAccount(out count, capitalAccount, strPassword, cond, start, page, ref errorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.QH_TodayTradeTableInfo[] queryIfTrade(out int count, out string strErrorMessage, string capitalAccount, string strPassword, int start, int page, XhDoQueryService.FuturesTradeConditionFindEntity cond)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.QH_TodayTradeTableInfo[] t = doQueryClient.FuturesTodayTradeFindByXhCapitalAccount(out count, out strErrorMessage, capitalAccount, strPassword, cond, start, page);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public XhDoQueryService.QH_HistoryTradeTableInfo[] queryIfHistoryTrade(out int count, string capitalAccount, string strPassword, XhDoQueryService.FuturesTradeConditionFindEntity cond, int start, int page, ref string strErrorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.QH_HistoryTradeTableInfo[] t = doQueryClient.FuturesHistoryTradeFindByXhCapitalAccount(out count, capitalAccount, strPassword, cond, start, page, ref strErrorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.FuturesHoldFindResultEntity[] queryIfHold(out int count, string capitalAccount, string strPassword, XhDoQueryService.FuturesHoldConditionFindEntity cond, int start, int page, ref string strErrorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.FuturesHoldFindResultEntity[] t = doQueryClient.FuturesHoldFind(out count, capitalAccount, strPassword, cond, start, page, ref strErrorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public XhDoQueryService.FuturesCapitalEntity getIfCapital(string strFundAccountId, XhDoQueryService.TypesCurrencyType currencyType, string userPassword, ref string strErrorMessage)
        {
            XhDoQueryService.TraderFindClient doQueryClient = new TraderFindClient();
            try
            {
                XhDoQueryService.FuturesCapitalEntity t = doQueryClient.FuturesCapitalFind(strFundAccountId, currencyType, userPassword, ref strErrorMessage);
                doQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (doQueryClient != null)
                {
                    doQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

        public DoCommonQuery.FuturesCapitalEntity getIfCapital2(string userId, int accountType, DoCommonQuery.TypesCurrencyType currencyType, string userPassword, ref string strErrorMessage)
        {
            DoCommonQuery.TraderQueryClient commonQueryClient = new DoCommonQuery.TraderQueryClient();
            try
            {
                DoCommonQuery.FuturesCapitalEntity t = commonQueryClient.PagingQueryFuturesCapital(userId, accountType, currencyType, userPassword, ref strErrorMessage);
                commonQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (commonQueryClient != null)
                {
                    commonQueryClient.Abort();
                }
                throw new Exception(ex.Message);
            }
        }

        /**************************融资融券*******************************/
        public RZRJOrderResponse rzrjDoOrder(DoRZRJOrderService.RZRJOrderRequest orderInfo)
        {
            DoRZRJOrderService.RZRJDoOrderClient rzrjDoOrderClient = new RZRJDoOrderClient();
            try
            { 
                RZRJOrderResponse t = rzrjDoOrderClient.DoRZRJOrder(orderInfo);
                rzrjDoOrderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjDoOrderClient != null)
                {
                    rzrjDoOrderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool rzrjCancelOrder(string orderId, ref string message)
        {
            DoRZRJOrderService.RZRJDoOrderClient rzrjDoOrderClient = new RZRJDoOrderClient();
            try
            { 
                bool t = rzrjDoOrderClient.CancelRZRJOrder(orderId, ref message);
                rzrjDoOrderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjDoOrderClient != null)
                {
                    rzrjDoOrderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_TodayEntrust[] getRzrjTodayOrder(out int total, out string errorMsg, string userID, string pwd, RZRJEntrustConditionFindEntity cond, DoRZRJQueryService.PagingInfo pageInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                RZRJ_TodayEntrust[] t = rzrjTraderQueryClient.PagingQueryTodayEntrustInfo(out total, out errorMsg, userID, pwd, cond, pageInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_HistoryEntrust[] getRzrjHistoryOrder(out int total, out string errorMsg, string userID, string pwd, RZRJEntrustConditionFindEntity cond, DoRZRJQueryService.PagingInfo pageInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            {
                RZRJ_HistoryEntrust[] t = rzrjTraderQueryClient.PagingQueryHistoryEntrustInfo(out total, out errorMsg, userID, pwd, cond, pageInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_TodayTrade[] getRzrjTodayTrade(out int total, out string errorMsg, string userID, string pwd, RZRJTradeConditionFindEntity cond, DoRZRJQueryService.PagingInfo pageInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            {
                RZRJ_TodayTrade[] t = rzrjTraderQueryClient.PagingQueryTodayTrade(out total, out errorMsg, userID, pwd, cond, pageInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_HistoryTrade[] getRzrjHistoryTrade(out int total, out string errorMsg, string userID, string pwd, RZRJTradeConditionFindEntity cond, DoRZRJQueryService.PagingInfo pageInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            {
                RZRJ_HistoryTrade[] t = rzrjTraderQueryClient.PagingQueryHistoryTrade(out total, out errorMsg, userID, pwd, cond, pageInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJHoldFindResultEntity[] getRzrjAccountHoldDetail(out int count, string userId, string strPassword, RZRJHoldConditionFindEntity cond, int start, int pageLength, ref string strErrorMessage)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                RZRJHoldFindResultEntity[] t = rzrjTraderQueryClient.PagingQueryHold(out count, userId, strPassword, cond, start, pageLength, ref strErrorMessage);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_HoldAccount[] getRzrjAccountHoldSimple(out string errorMsg, string userID, DoRZRJQueryService.QueryTypeQueryCurrencyType currencytype)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                RZRJ_HoldAccount[] t = rzrjTraderQueryClient.QueryAccountHoldTableByUserID(out errorMsg, userID, currencytype);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJCapitalEntity getRzrjCapital(string strFundAccountId, int currencyType, string userPassword, ref string strErrorMessage)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            {
                RZRJCapitalEntity t = rzrjTraderQueryClient.RZRJCapitalFind(strFundAccountId, currencyType, userPassword, ref strErrorMessage);
                rzrjTraderQueryClient.Abort();
                return t; 
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /*********************融资融券合约查询*************************/
        public DoRZRJQueryService.RZRJ_Liabilities[] getUnclosedRzLiabilities(out int total, out string errorMsg, string userID, string pwd, RZRJLiabilitiesFindEntity cond, DoRZRJQueryService.PagingInfo pagingInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                DoRZRJQueryService.RZRJ_Liabilities[] t = rzrjTraderQueryClient.PagingQueryLiabilitiesInfo(out total, out errorMsg, userID, pwd, cond, pagingInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }  
        }


        public DoRZRJQueryService.RZRQ_LiabilitiesHistory[] getClosedRzLiabilities(out int total, out string errorMsg, string userID, string pwd, RZRJLiabilitiesFindEntity cond, DoRZRJQueryService.PagingInfo pagingInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                DoRZRJQueryService.RZRQ_LiabilitiesHistory[] t = rzrjTraderQueryClient.PagingLiabilitiesHistoryInfo(out total, out errorMsg, userID, pwd, cond, pagingInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public DoRZRJQueryService.RZRJ_RJLiabilities[] getUnclosedRjLiabilities(out int total, out string errorMsg, string userID, string pwd, RZRJLiabilitiesFindEntity cond, DoRZRJQueryService.PagingInfo pagingInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                DoRZRJQueryService.RZRJ_RJLiabilities[] t = rzrjTraderQueryClient.PagingQueryRJLiabilitiesInfo(out total, out errorMsg, userID, pwd, cond, pagingInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public DoRZRJQueryService.RZRQ_RQLiabilitiesHistory[] getClosedRjLiabilities(out int total, out string errorMsg, string userID, string pwd, RZRJLiabilitiesFindEntity cond, DoRZRJQueryService.PagingInfo pagingInfo)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                DoRZRJQueryService.RZRQ_RQLiabilitiesHistory[] t = rzrjTraderQueryClient.PagingRJLiabilitiesHistoryInfo(out total, out errorMsg, userID, pwd, cond, pagingInfo);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /*********************资产，持仓等查询*************************/
        public RZRQComputerResultEntity getTradeMaxAmount(out string errMsg, RZRQComputeAmount result)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                RZRQComputerResultEntity t = rzrjTraderQueryClient.RZRQTradeMaxAmountFind(out errMsg, result);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRQCreditAssetsEntity getRzrjCreditAsset(out string errorMsg, string userID, string pwd, int currencyType)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                RZRQCreditAssetsEntity t = rzrjTraderQueryClient.QueryCreditAssets(out errorMsg, userID, pwd, currencyType);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_CapitalExtendTable[] getRzrjCapitalExtendTable(out string errorMsg, string userId, string userPassword, int currencyType)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            {
                RZRJ_CapitalExtendTable[] t = rzrjTraderQueryClient.QueryCapitalExtendTableByuserId(out errorMsg, userId, userPassword, currencyType);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool getMaintainGuarantyRatio(out decimal maintainGuarantyRatio, out string errorMsg, string userID, string pwd, int currencyType)
        {
            DoRZRJQueryService.RZRJTraderQueryClient rzrjTraderQueryClient = new RZRJTraderQueryClient();
            try
            { 
                bool t = rzrjTraderQueryClient.GetMaintainGuarantyRatio(out maintainGuarantyRatio, out errorMsg, userID, pwd, currencyType);
                rzrjTraderQueryClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjTraderQueryClient != null)
                {
                    rzrjTraderQueryClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /*****************************标的物*****************************/
        public RZRJ_BourseUnderlyingCode[] getRzrjUnderLyingList(out int total, out string message, string code, MPagingInfo pagingInfo)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                RZRJ_BourseUnderlyingCode[] t = rzrjBasicProviderClient.QueryUnderlyingCodePager(out total, out message, code, pagingInfo);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool isUnderLyingStock(out string message, string code)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                bool t = rzrjBasicProviderClient.ExistsUnderlyingCode(out message, code);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            } 
        }


        public RZRJ_SecurityUnderlyingCode[] getRzrjCompanyUnderLyingList(out int total, out string msg, int securityCompanyID, string code, MPagingInfo pagingInfo)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                RZRJ_SecurityUnderlyingCode[] t = rzrjBasicProviderClient.GetSecurityUnderlyingCodePager(out total, out msg, securityCompanyID, code, pagingInfo);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_SecurityUnderlyingCode[] getRzrjCompanyUnderLyingCode(int securityCompanyID, string code)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            {
                RZRJ_SecurityUnderlyingCode[] t = rzrjBasicProviderClient.QuerySecurityUnderlyingCode(securityCompanyID, code);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /*************************担保品**************************/
        public RZRJ_BourseMortagagedCode[] getRzrjMortagageList(out int total, out string message, string code, int codeBelongBourse, int priorLevel, MPagingInfo pagingInfo)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                RZRJ_BourseMortagagedCode[] t = rzrjBasicProviderClient.QueryMortagageCodePager(out total, out message, code, codeBelongBourse, priorLevel, pagingInfo);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            } 
        }


        public bool isMortagageStock(out string message, string code)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                bool t = rzrjBasicProviderClient.ExistsMortagagedCode(out message, code);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public RZRJ_SecurityMortagagedCode[] getRzrjCompanyMortagageList(out int total, out string msg, string code, int securityCompanyID, MPagingInfo pagingInfo)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                RZRJ_SecurityMortagagedCode[] t = rzrjBasicProviderClient.GetSecurityMortagagedCodePager(out total, out msg, securityCompanyID, code, pagingInfo);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        /***********************融资融券开户*************************/
        public int addRzrjBasicInfo(out string msg, RZRJ_TraderBasicInfo[] traderBasicInfoList)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                int t = rzrjBasicProviderClient.AddTraderBasicInfoList(out msg, traderBasicInfoList);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool addRzrjCreditLimit(out string msg, WcfRZRJBasicProviderService.RZRJ_PersonLimitCredit[] modelList, int[] userIdList)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                bool t = rzrjBasicProviderClient.AddRZRJ_PersonLimitCreditInfo(out msg, modelList, userIdList);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool modifyRzrjCreditLimit(ref string msg, WcfRZRJBasicProviderService.RZRJ_PersonLimitCredit[] modelList)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            {
                bool t = rzrjBasicProviderClient.UpdateRZRJ_PersonLimitCreditInfo(modelList, ref msg);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }


        public bool rzrjFundTransfer(out string outMessage, WcfRZRJBasicProviderService.FreeTransferEntity freeTransfer, WcfRZRJBasicProviderService.TypesCurrencyType currencyType)
        {
            WcfRZRJBasicProviderService.RZRJBasicDataOperationContractClient rzrjBasicProviderClient = new RZRJBasicDataOperationContractClient();
            try
            { 
                bool t = rzrjBasicProviderClient.BankAndRZRJAccountsFreeTransferFunds(out outMessage, freeTransfer, currencyType);
                rzrjBasicProviderClient.Abort();
                return t;
            }
            catch (Exception ex)
            {
                if (rzrjBasicProviderClient != null)
                {
                    rzrjBasicProviderClient.Abort(); 
                }
                throw new Exception(ex.Message);
            }
        }

    }
}
